﻿@{
    ViewBag.Title = "添加地址";
    Layout = "~/Areas/WeiXinAreas/Views/Shared/_LayoutWeui.cshtml";
}
<form id="form1">
    <div class="weui-cells__title">地址信息</div>
    <div class="weui-cells weui-cells_form">
        <div class="weui-cell">
            <div class="weui-cell__hd"><label for="" class="weui-label">所在地区</label></div>
            <div class="weui-cell__bd">
                <input type="hidden" value="@ViewData["F_Id"]" id="F_Id" name="F_Id" />
                <input type="hidden" value="@ViewData["F_UserId"]" id="F_UserId" name="F_UserId" />
                <input class="weui-input" type="text" value="@ViewData["F_City"]"  placeholder="请选择所在地区" id="F_City" name="F_City">
            </div>
        </div>
        <div class="weui-cell">
            <div class="weui-cell__hd"><label for="" class="weui-label">详情地址</label></div>
            <div class="weui-cell__bd">
                <input class="weui-input"  value="@ViewData["F_Add"]"  id="F_Add" name="F_Add">
            </div>
        </div>
        <div class="weui-cell">
            <div class="weui-cell__hd"><label for="" class="weui-label">收货人</label></div>
            <div class="weui-cell__bd">
                <input class="weui-input" value="@ViewData["F_Name"]" id="F_Name" name="F_Name" placeholder="请输入收货人姓名">
            </div>
        </div>
        <div class="weui-cell">
            <div class="weui-cell__hd"><label for="" class="weui-label">手机号</label></div>
            <div class="weui-cell__bd">
                <input class="weui-input" value="@ViewData["F_Tele"]"   id="F_Tele" name="F_Tele" placeholder="请输入手机号">
            </div>
        </div>
    </div>
    <a href="javascript:submit();" class="weui-btn weui-btn_primary" style="margin-top:.5rem;background-color:#35a4fe;">提交<i class="weui-loading" style="display:none;"></i></a>
</form>
@section footScript
{
<script src="https://cdn.bootcss.com/jquery-weui/1.2.1/js/city-picker.min.js"></script>
<script>
    var pid="@ViewData["pid"]";
    $(function () {
        $("#F_City").cityPicker({
            title: "请选择收货地址"
        });
    });    
    function submit() {
        if (yan() != false) {
            $(".weui-loading").show();
            $.ajax({
                url: "submitAddress",
                data: $("#form1").serialize(),
                dataType: 'json',
                type: 'post',
                success: function (_data) {
                    if (_data > 0) {
                        location.replace("Address"+((pid&&pid.length>0)?"?pid="+pid:""));
                    } else {
                        $.alert("添加失败！");
                        $(".weui-loading").hide();
                    }
                }
            });
        }
    }
    function yan() {
        if ($("#F_City").val() == "") {
            $.alert("请输入所在地区!");
            return false;
        } 
        if ($("#F_Add").val() == "") {
            $.alert("请输入详细地址!");
            return false;
        }
        if ($("#F_Name").val() == '') {
            $.alert("请输入收货人姓名!");
            return false;
        }
        var haoma = $('#F_Tele').val();
        if(haoma==""){
            $.alert("请输入手机号码!");
            return false;
        }
        if (!(/^1[345789]\d{9}$/.test(haoma))) {
            $.alert("手机号码有误，请重填!");
            return false;
        }
        //var card = $("#F_IdCard").val();
        //if (card =="") {
        //    $.alert("请输入身份证号码!");
        //    return false;
        //}
        //if (!(/^(\d{15}$|^\d{18}$|^\d{17}(\d|X|x))$/.test(card))) {
        //    $.alert("身份证号码有误，请重填!");
        //    return false;
        //}
        return true;
    }
</script>
}